﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MHPL_DoTrangSuc.Data;

namespace MHPL_DoTrangSuc.ManHinh
{
    public partial class frmSua_HoaDon : Form
    {
        KetNoi kn = new KetNoi();
        public frmSua_HoaDon()
        {
            InitializeComponent();
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Bạn có muốn thoát không ?", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Error) == DialogResult.OK)
            {
                this.Close();
            }
        }

        private void btnHuyBo_Click(object sender, EventArgs e)
        {
            foreach (Control ctr in this.groupThongTinHD.Controls)
            {
                if ((ctr is TextBox) || (ctr is DateTimePicker) || (ctr is ComboBox))
                {
                    ctr.Text = "";
                }
            }
        }

        private void frmSua_HoaDon_Load(object sender, EventArgs e)
        {
            kn.ketnoi();

            hienthi();
        }

        public void hienthi()
        {
            string str;
            //str = "SELECT MaHoaDon,NgayLapHoaDon,SoTienThanhToan,MaDonHang,TenQT FROM HoaDon hd,QuanTri qt where hd.TenDNQT=qt.TenDNQT ";
            str = "SELECT MaHoaDon,NgayLapHoaDon,TenSP,SoLuongMua,GiaBanSP,GiamGia,SoTienThanhToan,TenQT FROM SanPham sp,ChiTietDonHang ctdh,DonHang dh, HoaDon hd WHERE hd.MaDonHang=dh.MaDonHang and dh.MaDonHang=ctdh.MaDonHang and ctdh.MaSP=sp.MaSP ";
              
            DataTable tb = new DataTable();
            tb.Load(kn.ThucHienReader(str));
            Load_ListView(lwThongTinChiTietHD, tb);
        }
        public void Load_ListView(ListView lvwName, DataTable tb)
        {
            lwThongTinChiTietHD.Items.Clear();
            for (int i = 0; i < tb.Rows.Count; i++)
            {
                string[] col = new string[tb.Columns.Count];
                for (int j = 0; j < tb.Columns.Count; j++)
                {
                    col[j] = tb.Rows[i][j].ToString();
                }
                ListViewItem lvItem = new ListViewItem(col);
                lvwName.Items.Add(lvItem);
            }
        }

        private void lwThongTinChiTietHD_SelectedIndexChanged(object sender, EventArgs e)
        {
            int i = lwThongTinChiTietHD.FocusedItem.Index;
            if (i < 0)
                return;
           /* txtTenQT.Text = lwThongTinChiTietHD.Items[i].SubItems[5].Text;
            TxtHoTenKH.Text = lwThongTinChiTietHD.Items[i].SubItems[0].Text;
            cbGioiTinh.Text = listViewKH.Items[i].SubItems[1].Text;
            txtEmail.Text = listViewKH.Items[i].SubItems[4].Text;

            TxtDienThoai.Text = listViewKH.Items[i].SubItems[3].Text;
            TxtDiaChi.Text = listViewKH.Items[i].SubItems[2].Text;*/
        }

        }
    }

